********************************************************************************
*** Voting for Populism in Europe Replication Files
*** Table A7: SUREG: Vote Share, 1990-2018
*** Table A8: SUREG: Vote Share w/ Interactions, 1990-2018
*** Table A9: SUREG: Vote Share, 1990-2018 Low Wage Imports
*** Table A10: SUREG: Vote Share w/ Interactions, 1990-2018 Low Wage Imports
***
*** Required data files: "imputed_econdata_voteshare_merged.dta"
***                     
*** 
*** Created by: Thomas Cunningham
*** Date: 5 January 2021
******************************************************************

clear all
version 16.1
cd ..
 	
use "data/imputed/imputed_econdata_voteshare_merged.dta", clear

cap program drop mysuest
program mysuest, eclass properties(mi)
        version 13.1
    args model1 model2 model3 model4 model5

        qui `model1'
        estimates store est1
        qui `model2'
        estimates store est2
		qui `model3'
        estimates store est3
		qui `model4'
        estimates store est4
		qui `model5'
        estimates store est5
        suest est1 est2 est3 est4 est5, vce(cluster nuts_encoded)
        estimates drop est1 est2 est3 est4 est5
        
        ereturn local title "Seemingly unrelated estimation"
end



*------------- Relabel Key Covariates ----------------------------------- 
la var shock_china_ind_L1 "China Shock"
la var shock_lowwage_ind_L1 "Low-Wage Imp Shock"
la var rti_region_L1 "RTI Region"
la var shock_fgn92_L1 "Immigration Shock"
la var shock_robots_mfg_L1 "Robot Shock"
la var shock_fdi_in_ind_L1 "FDI Shock"
la var reg_ict_emp_mfg_L1 "ICT"
la var postcrisis "Post-Crisis"	

// https://www.stata.com/support/faqs/statistics/combine-results-with-multiply-imputed-data/
// program to use suest with mi data
//////////////////////////////////////////////////////

********************************************************************************
*** TABLE A7: Vote share SUR (No interaction)
********************************************************************************

local controls1 "shock_fdi_in_ind_L1  shock_robots_mfg_L1 "
local controls2 "shock_fdi_in_ind_L1  shock_robots_mfg_L1 rti_region_L1 " 
local controls3 "shock_fdi_in_ind_L1  shock_robots_mfg_L1 rti_region_L1   shock_fgn92_L1 "

local X "i.cwdyad"

forval u=1/3{
	* Vote Shares
	mi estimate, post: mysuest "reg nuts2_right_pop_vs shock_china_ind_L1 i.postcrisis `controls`u'' `X'" "reg nuts2_main_right_vs shock_china_ind_L1 i.postcrisis `controls`u'' `X'"  "reg nuts2_main_left_vs shock_china_ind_L1 i.postcrisis `controls`u'' `X'"  "reg nuts2_left_pop_vs shock_china_ind_L1 i.postcrisis `controls`u'' `X'" "reg nuts2_other_parties_vs shock_china_ind_L1 i.postcrisis `controls`u'' `X'"
		est sto mysu_`u'_share	
}

************************************************************
****   Table A7, Panel A
************************************************************
esttab mysu_1_share using "output/appendix/TableA7_a.tex", replace /*
*/  cells(b(star fmt(%9.3f)) se(par)) stats(N r2, fmt(%9.0g %9.3f)) unstack starlevels(* .1 ** .05 *** .01) /*
	*/ label legend keep(est1_mean: est2_mean: est3_mean: est4_mean: est5_mean:) drop(*.cwdyad) /*
	*/ title("SUREG: Vote, 1990-2018} \begin{threeparttable") nonumber  nonotes compress ///


	
************************************************************
****   Table A7, Panel B 
************************************************************
	
esttab mysu_2_share using "output/appendix/TableA7_b.tex", replace /*
*/  cells(b(star fmt(%9.3f)) se(par)) stats(N r2, fmt(%9.0g %9.3f)) unstack starlevels(* .1 ** .05 *** .01) /*
	*/ label legend keep(est1_mean: est2_mean: est3_mean: est4_mean: est5_mean:) drop(*.cwdyad) /*
	*/ title("SUREG: Vote Difference, 1990-2018} \begin{threeparttable") nonumber  nonotes compress ///
 
	
*************************************************************
**** Table A7 Panel C
*************************************************************
esttab mysu_3_share using "output/appendix/TableA7_c.tex", replace /*
*/  cells(b(star fmt(%9.3f)) se(par)) stats(N r2, fmt(%9.0g %9.3f)) unstack starlevels(* .1 ** .05 *** .01) /*
	*/ label legend keep(est1_mean: est2_mean: est3_mean: est4_mean: est5_mean:) drop(*.cwdyad) /*
	*/ title("SUREG: Vote Difference, 1990-2018} \begin{threeparttable") nonumber  nonotes compress ///

	

****************************************************************	
*** TABLE A8: Vote Share SUR (Post Crisis X China Shock Interaction)
****************************************************************

forval u=1/3{
	* Vote Shares
	mi estimate, post: mysuest "reg nuts2_right_pop_vs c.shock_china_ind_L1##i.postcrisis `controls`u'' `X'" "reg nuts2_main_right_vs c.shock_china_ind_L1##i.postcrisis `controls`u'' `X'"  "reg nuts2_main_left_vs c.shock_china_ind_L1##i.postcrisis `controls`u'' `X'"  "reg nuts2_left_pop_vs c.shock_china_ind_L1##i.postcrisis `controls`u'' `X'" "reg nuts2_other_parties_vs c.shock_china_ind_L1##i.postcrisis `controls`u'' `X'"
		est sto mysu_`u'_share_int	
}

************************************************************
****   Table A8, Panel A
************************************************************
esttab mysu_1_share_int using "output/appendix/TableA8_a.tex", replace /*
*/  cells(b(star fmt(%9.3f)) se(par)) stats(N r2, fmt(%9.0g %9.3f)) unstack starlevels(* .1 ** .05 *** .01) /*
	*/ label legend keep(est1_mean: est2_mean: est3_mean: est4_mean: est5_mean:) drop(*.cwdyad) /*
	*/ title("SUREG: Vote, 1990-2018} \begin{threeparttable") nonumber  nonotes compress ///


	
************************************************************
****   Table A8, Panel B 
************************************************************
	
esttab mysu_2_share_int using "output/appendix/TableA8_b.tex", replace /*
*/  cells(b(star fmt(%9.3f)) se(par)) stats(N r2, fmt(%9.0g %9.3f)) unstack starlevels(* .1 ** .05 *** .01) /*
	*/ label legend keep(est1_mean: est2_mean: est3_mean: est4_mean: est5_mean:) drop(*.cwdyad) /*
	*/ title("SUREG: Vote Difference, 1990-2018} \begin{threeparttable") nonumber  nonotes compress ///
 

*************************************************************
**** Table A8 Panel C
*************************************************************
esttab mysu_3_share_int using "output/appendix/TableA8_c.tex", replace /*
*/  cells(b(star fmt(%9.3f)) se(par)) stats(N r2, fmt(%9.0g %9.3f)) unstack starlevels(* .1 ** .05 *** .01) /*
	*/ label legend keep(est1_mean: est2_mean: est3_mean: est4_mean: est5_mean:) drop(*.cwdyad) /*
	*/ title("SUREG: Vote Difference, 1990-2018} \begin{threeparttable") nonumber  nonotes compress ///

	

	
********************************************************************************
**** SUREG Low-Wage 
********************************************************************************
*** Vote share SUR (No interaction)
forval u=1/3{
	* Vote Shares
	mi estimate, post: mysuest "reg nuts2_right_pop_vs shock_lowwage_ind_L1 i.postcrisis `controls`u'' `X'" "reg nuts2_main_right_vs shock_lowwage_ind_L1 i.postcrisis `controls`u'' `X'"  "reg nuts2_main_left_vs shock_lowwage_ind_L1 i.postcrisis `controls`u'' `X'"  "reg nuts2_left_pop_vs shock_lowwage_ind_L1 i.postcrisis `controls`u'' `X'" "reg nuts2_other_parties_vs shock_lowwage_ind_L1 i.postcrisis `controls`u'' `X'"
		est sto mysu_`u'_lwshare	
}

************************************************************
****   Table A9, Panel A
************************************************************
esttab mysu_1_lwshare using "output/appendix/TableA9_a.tex", replace /*
*/  cells(b(star fmt(%9.3f)) se(par)) stats(N r2, fmt(%9.0g %9.3f)) unstack starlevels(* .1 ** .05 *** .01) /*
	*/ label legend keep(est1_mean: est2_mean: est3_mean: est4_mean: est5_mean:) drop(*.cwdyad) /*
	*/ title("SUREG: Vote, 1990-2018} \begin{threeparttable") nonumber  nonotes compress ///


	
************************************************************
****   Table A9, Panel B 
************************************************************
	
esttab mysu_2_lwshare using "output/appendix/TableA9_b.tex", replace /*
*/  cells(b(star fmt(%9.3f)) se(par)) stats(N r2, fmt(%9.0g %9.3f)) unstack starlevels(* .1 ** .05 *** .01) /*
	*/ label legend keep(est1_mean: est2_mean: est3_mean: est4_mean: est5_mean:) drop(*.cwdyad) /*
	*/ title("SUREG: Vote Difference, 1990-2018} \begin{threeparttable") nonumber  nonotes compress ///

	
*************************************************************
**** Table A9 Panel C
*************************************************************
esttab mysu_3_lwshare using "output/appendix/TableA9_c.tex", replace /*
*/  cells(b(star fmt(%9.3f)) se(par)) stats(N r2, fmt(%9.0g %9.3f)) unstack starlevels(* .1 ** .05 *** .01) /*
	*/ label legend keep(est1_mean: est2_mean: est3_mean: est4_mean: est5_mean:) drop(*.cwdyad) /*
	*/ title("SUREG: Vote Difference, 1990-2018} \begin{threeparttable") nonumber  nonotes compress ///

	

****************************************************************	
*** Vote Share SUR (Post Crisis X China Shock Interaction)
****************************************************************

forval u=1/3{
	* Vote Shares
	mi estimate, post: mysuest "reg nuts2_right_pop_vs c.shock_lowwage_ind_L1##i.postcrisis `controls`u'' `X'" "reg nuts2_main_right_vs c.shock_lowwage_ind_L1##i.postcrisis `controls`u'' `X'"  "reg nuts2_main_left_vs c.shock_lowwage_ind_L1##i.postcrisis `controls`u'' `X'"  "reg nuts2_left_pop_vs c.shock_lowwage_ind_L1##i.postcrisis `controls`u'' `X'" "reg nuts2_other_parties_vs c.shock_lowwage_ind_L1##i.postcrisis `controls`u'' `X'"
		est sto mysu_`u'_lwshare_int	
}

************************************************************
****   Table A10, Panel A
************************************************************
esttab mysu_1_lwshare_int using "output/appendix/TableA10_a.tex", replace /*
*/  cells(b(star fmt(%9.3f)) se(par)) stats(N r2, fmt(%9.0g %9.3f)) unstack starlevels(* .1 ** .05 *** .01) /*
	*/ label legend keep(est1_mean: est2_mean: est3_mean: est4_mean: est5_mean:) drop(*.cwdyad) /*
	*/ title("SUREG: Vote, 1990-2018} \begin{threeparttable") nonumber  nonotes compress ///


	
************************************************************
****   Table A10, Panel B 
************************************************************
	
esttab mysu_2_lwshare_int using "output/appendix/TableA10_b.tex", replace /*
*/  cells(b(star fmt(%9.3f)) se(par)) stats(N r2, fmt(%9.0g %9.3f)) unstack starlevels(* .1 ** .05 *** .01) /*
	*/ label legend keep(est1_mean: est2_mean: est3_mean: est4_mean: est5_mean:) drop(*.cwdyad) /*
	*/ title("SUREG: Vote Difference, 1990-2018} \begin{threeparttable") nonumber  nonotes compress ///


*************************************************************
**** Table A10 Panel C
*************************************************************
esttab mysu_3_lwshare_int using "output/appendix/TableA10_c.tex", replace /*
*/  cells(b(star fmt(%9.3f)) se(par)) stats(N r2, fmt(%9.0g %9.3f)) unstack starlevels(* .1 ** .05 *** .01) /*
	*/ label legend keep(est1_mean: est2_mean: est3_mean: est4_mean: est5_mean:) drop(*.cwdyad) /*
	*/ title("SUREG: Vote Difference, 1990-2018} \begin{threeparttable") nonumber  nonotes compress ///

	
